package com.xuwenjin.jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;

public class TestTX {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        Transaction multi = jedis.multi();
//        jedis.watch("key");
        try {
            Response<String> set = multi.set("aa", "bb");
            multi.exec();
        } catch (Exception e) {
            multi.discard();//放弃事务
            e.printStackTrace();
        } finally {
            jedis.close();
        }
    }
}
